<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:de="urn:oasis:names:tc:emergency:EDXL:DE:1.0" xmlns:sr="http://icnet.mitre.org/mEXL/SitRep/" xmlns:xnl="urn:oasis:names:tc:ciq:xnl:3" xmlns:cot="urn:cot:mitre:org" xmlns:csharp="http://csharp.org">
	<xsl:import href="get-address.xsl"/>
	<xsl:template match="/">
		<html>
			<head>
				<style>

		body {
			font-family: sans-serif;
		}
								h1, h2, h3, h4, p {
        padding: 0;
        margin: 0;
        text-align: center;
      }
      
      #wrapper {
        border-top: 1px solid DimGray;
        border-left: 1px solid DimGray;
        border-right: 1px solid DimGray;
        min-width: 310px
      }
      
      #title, #address, #sender-info, #observation, #images, #point {
        border-bottom: 1px solid DimGray;
        padding: 0.25em;
      }
      
      #title {
        color: white;
        background-color: black;
        text-align: center;
      }
      
      #title img {
		float: left;
		max-height: 37px;
      }
      
      #title.mayday {
		  background-color: #dd0000;
      }
      
      #address {
        text-align: center;
      }
      
      #address span {
		  font-weight: bold;
      }
      
      #lat-long {
		  font-weight: normal;
		  font-size: 0.8em;
      }
      
      #header h1 {
        display: inline;
        padding: 0 0.5em 0 0;
      }
      
      #images {
        padding: 0.25em;
      }
      
      .image {
		  text-align: center;
        padding: 0 0.5em 0;

        display: block;
        margin-left: auto;
        margin-right: auto;
      }
      
      .image img {
              max-width: 475px;
      }
      
      .caption {
        text-align: center;
      }
      
      #sender-info {
        text-align: center;
      }
      
      
      #observation-data, #point-data {
        padding: 0 0 0 0.5em;
        min-width:100%;
        max-width:100%;
        vertical-align:top
      }
      
      #observation-data th, #point-data th {
        text-align: left;
        width: 125px;
        vertical-align:top
      }
      
      #observation-data table, #point-data table {
      margin-left:auto;		margin-right:auto;
      }
      
      .clearing {
        clear: both;
      }
				</style>
			</head>
			<body>
				<div id="wrapper">
					<div id="header">
						<div id="title">
							<h1>
								<xsl:choose>
									<xsl:when test="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep">
										Field Observation - <xsl:value-of select="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep/SituationObservation/ObservationType"/>
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="de:EDXLDistribution/de:distributionID"/>
									</xsl:otherwise>
								</xsl:choose>
							</h1>
						</div>
						<div id="address">Near <span>
							<xsl:choose>
								<xsl:when test="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep">
									
									<xsl:variable name="googleAddress"><xsl:value-of select="csharp:GetAddressFromLatLon(
										substring-before(de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep/ObservationLocation,' '), 
										substring-after(de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep/ObservationLocation,' '))" /></xsl:variable>
									<xsl:if test="$googleAddress != ''">
										<xsl:value-of select="$googleAddress"/>
									</xsl:if>
								<div id="lat-long"><xsl:value-of select="substring-before(de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep/ObservationLocation,' ')"/>, <xsl:value-of select="substring-after(de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep/ObservationLocation,' ')"/></div>
								</xsl:when>
								
								<xsl:when test="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/cot:event">
									<xsl:variable name="googleAddress"><xsl:value-of select="csharp:GetAddressFromLatLon(
										de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/cot:event/point/@lat,
										de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/cot:event/point/@lon)" /></xsl:variable>
										<xsl:if test="$googleAddress != ''">
										<xsl:value-of select="$googleAddress"/>
									</xsl:if>
								<div id="lat-long"><xsl:value-of select="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/cot:event/point/@lat"/>, <xsl:value-of select="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/cot:event/point/@lon"/></div>
								</xsl:when>
							</xsl:choose>
							
						</span>
						</div>
					</div>
					<div id="content">
						<div id="sender-info">
							<p>
								<strong>Sent by </strong>
								<xsl:value-of select="de:EDXLDistribution/de:senderID"/>
								<strong> at </strong>
								<xsl:value-of select="de:EDXLDistribution/de:dateTimeSent"/>
							</p>
						</div>
						
						
						<xsl:for-each select="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/sr:SitRep">
							<div id="observation">
								<h3>Field Observation</h3>
								<div id="observation-data">
									<table>
										<tr>
											<th>Observed by:</th>
											<td>
												<xsl:value-of select="PreparedBy/xnl:PersonName/xnl:NameElement"/>
											</td>
										</tr>
										<tr>
											<th>Type:</th>
											<td>
												<xsl:value-of select="SituationObservation/ObservationType"/>
											</td>
										</tr>
										<tr>
											<th>Remarks:</th>
											<td>
												<xsl:value-of select="SituationObservation/ObservationText"/>
											</td>
										</tr>
										<xsl:if test="SituationObservation/ImmediateNeeds != ''">
											<tr>
												<th>Immediate Needs:</th>
												<td><xsl:value-of select="SituationObservation/ImmediateNeeds"/></td>
											</tr>
										</xsl:if>
										<xsl:if test="Certainty != ''">
											<tr>
												<th>Certainty:</th>
												<td><xsl:value-of select="Certainty"/></td>
											</tr>
										</xsl:if>
										<xsl:if test="Urgency != ''">
											<tr>
												<th>Urgency:</th>
												<td><xsl:value-of select="Urgency"/></td>
											</tr>
										</xsl:if>
									</table>
								</div>
							</div>
						</xsl:for-each>
						
						<xsl:for-each select="de:EDXLDistribution/de:contentObject">
							<xsl:if test="de:nonXMLContent/de:mimeType='image/jpeg'">
								<div id="images">
									<h3>Field Images</h3>
									<div class="image">
										<img alt="Embedded Image">
											<xsl:attribute name="src"><xsl:value-of select="concat('data:image/png;base64,', de:nonXMLContent/de:contentData, '')"/></xsl:attribute>
										</img>
										<div class="caption">
											<xsl:value-of select="substring-before(de:contentDescription,'[')"/>
										</div>
									</div>
									<div class="clearing"/>
								</div>
							</xsl:if>
						</xsl:for-each>
						
						
						<xsl:for-each select="de:EDXLDistribution/de:contentObject/de:xmlContent/de:embeddedXMLContent/cot:event">
							<div id="point">
								<xsl:choose>
									<xsl:when test="@type = 'a-f-g-9-1-1'">
										<h3>MAYDAY Message</h3>
									</xsl:when>
									<xsl:otherwise>
										<h3>Point Message</h3>
									</xsl:otherwise>
								</xsl:choose>
								<div id="point-data">
									<table>
										<tr>
											<th>Lat/Long:</th>
											<td>
												<xsl:value-of select="point/@lat"/>, <xsl:value-of select="point/@lon"/>
											</td>
										</tr>
										<xsl:if test="cot:detail/cot:remarks != ''">
											<tr>
												<th>Remarks:</th>
												<td>
													<xsl:value-of select="cot:detail/cot:remarks"/>
												</td>
											</tr>
										</xsl:if>
										<xsl:for-each select="cot:detail/cot:__icnet/cot:beacon">
											<tr>
												<th>Phone Number:</th>
												<td><xsl:value-of select="@number"/></td>
											</tr>
											<tr>
												<th>Battery Strength:</th>
												<td><xsl:value-of select="@battery * 100"/>%</td>
											</tr>
											<tr>
												<th>Signal:</th>
												<td><xsl:value-of select="@signal"/> dBm</td>
											</tr>
										</xsl:for-each>
									</table>
								</div>
							</div>
						</xsl:for-each>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
